*************************************************************************
*																		*
*					Code Political involvement								*
*																		*
**************************************************************************

/* 
Replication Material for:
Maria Preißinger & Harald Schoen (2016): It's not always the campaign - 
Explaining inter-elction switching in Germany, 2009-2013. Electoral Studies.

Date: Sep 2016
*/


*-----------------------------------------------------------
* Attitudes
*-----------------------------------------------------------


* Nuclear energy
fre b_kp2_2860e
fre a_kp7_1370_7 a_kp7_1370_11

foreach welle of numlist 2 5 {
gen b_kern`welle' = (b_kp`welle'_2860e-1) if b_kp`welle'_2860e>0
}

lab var b_kern2 "start campaign nuclear energy"
lab define kern ///
	0 "contra nuclear energy" ///
	4 "pro nuclear energy" , replace
	
lab val b_kern? kern
	
fre *kern*


* help for indebted EURO-countries
lookfor Hilfe			
fre b_kp?_2830		

foreach welle of numlist 3 5 7 {
gen b_schuldhilfe`welle' = 7-b_kp`welle'_2830 if b_kp`welle'_2830>0
}

fre b_schuldhilfe?


** economic situtaion
foreach welle in 1 3 5 7 {
	gen a_wslage`welle' = 5-a_kp`welle'_820
	replace a_wslage`welle' = . if a_kp`welle'_820==99
}
lab define wslage ///
	4 "very good" ///
	0 "very bad", replace
	
fre a_wslage*	
foreach welle in  1 3 5 7 {
lab var a_wslage`welle' "general economic situation"
lab val a_wslage`welle' wslage
}


foreach welle in 1 4 7 {
	gen b_wslage`welle' = 5-b_kp`welle'_820
	replace b_wslage`welle' = . if b_kp`welle'_820<1
}
foreach welle in  1 4 7 {
lab var b_wslage`welle' "general economic situation"
lab val b_wslage`welle' wslage
}

fre b_wslage*


* Feelings towards AfD
foreach welle of numlist 1/7{
gen b_skaloafd`welle' = b_kp`welle'_430i-1
replace b_skaloafd`welle' = . if b_kp`welle'_430i==-99 | ///
	b_kp`welle'_430i==-95 | b_kp`welle'_430i==-93 
}
tab b_skaloafd5 b_kp5_430i


* Merkel (CDU)  2009
foreach welle of numlist 1/7 {
	gen a_kandcdu`welle' = a_kp`welle'_650a
	replace a_kandcdu`welle' = . if a_kp`welle'_650a>11
}

* Steinmeier (SPD) 2009
foreach welle of numlist 1/7 {
	gen a_kandspd`welle' = a_kp`welle'_650b
	replace a_kandspd`welle' = . if a_kp`welle'_650b>11
}

* Merkel (CDU) 2013
foreach welle of numlist 1/7 {
	gen b_kandcdu`welle' = b_kp`welle'_650a
	recode b_kandcdu`welle' (-99=.) (-95=.) (-93=.) (-71=.)
}
* Steinbrück (SPD) 2013
foreach welle of numlist 1/7 {
	gen b_kandspd`welle' = b_kp`welle'_650b
	recode b_kandspd`welle' (-99=.) (-95=.) (-93=.) (-71=.)
}



*-----------------------------------------------------------------------------------
* Attitide change (continuous variables), directed and undirected:
* Between campaign change and within campaign change 
*------------------------------------------------------------------------------------

* Nuclar energy	
gen changekerndir_25 = b_kern5 - b_kern2		//direction of change within campaign
gen changekernabs_25 = abs(b_kern5 - b_kern2)	//undirected amount of change within campaign	

	
* Economic situation
gen changewslagedir_71 = b_wslage1-a_wslage7	//direction of change between campaign
gen changewslagedir_17 = b_wslage7-b_wslage1	//direction of change within campaign

gen changewslageabs_71 = abs(b_wslage1-a_wslage7)	//undirected amount of change between campaign	
gen changewslageabs_17 = abs(b_wslage7-b_wslage1)	//undirected amount of change within campaign	


* SPD candidate				
fre b_kandspd1	

gen changekandspdabs_71 = abs(b_kandspd1 - a_kandspd7)
gen changekandspdabs_17 = abs(b_kandspd7 - b_kandspd1)	

gen changekandspddir_71 = b_kandspd1 - a_kandspd7
gen changekandspddir_17 = b_kandspd7 - b_kandspd1			

* cdu candidate
fre b_kandcdu1		

gen changekandcduabs_71 = abs(b_kandcdu1 - a_kandcdu7)
gen changekandcduabs_17 = abs(b_kandcdu7 - b_kandcdu1)	

gen changekandcdudir_71 = b_kandcdu1 - a_kandcdu7
gen changekandcdudir_17 = b_kandcdu7 - b_kandcdu1	

				
* AfD
fre b_skaloafd1

gen changeskaloafddir_17 = b_skaloafd7 - b_skaloafd1				
gen changeskaloafdabs_17 = abs(b_skaloafd7 - b_skaloafd1)				

lab var b_skaloafd1 "start campaign AFD"


* help for indebted EURO-countries
gen changeschuldhilfedir_37 = b_schuldhilfe7 - b_schuldhilfe3
gen changeschuldhilfeabs_37 = abs(b_schuldhilfe7 - b_schuldhilfe3)


lab var b_schuldhilfe3 "start campaign debt crisis"
lab var changeschuldhilfedir_37 "campaign change debt crisis (directed)"
lab var changeschuldhilfeabs_37 "campaign change debt crisis (undirected)"


*-----------------------------------------
* Categorize attitide change variables
*----------------------------------------


* Dichotomize undirected change variable	
foreach var of varlist change*abs_?? {
gen kat_`var' = `var'	
replace kat_`var' = 1 if `var'>0 & `var'~=.
}


* Categorize directed change variables
lab define katdir ///
	0 "negative change" ///
	1 "no change" ///
	2 "positive change", replace


foreach var of varlist change*dir_?? {
gen kat_`var' = `var'
replace kat_`var' = 0 if `var'<0 //negativ = 0 
replace kat_`var' = 2 if `var'>0 & `var'~=. //positiv = 2
replace kat_`var' = 1 if `var'==0 //no change=1
lab val kat_`var' katdir
}


* Categorize varaibles where no between campaign change available
gen kat_b_skaloafd1 = 1 if b_skaloafd1==5
replace kat_b_skaloafd1 = 0 if b_skaloafd1<5
replace kat_b_skaloafd1 = 2 if b_skaloafd1>5 & b_skaloafd1~=.

gen kat_b_kern2 = 1 if b_kern2==2
replace kat_b_kern2 = 0 if b_kern2<2
replace kat_b_kern2 = 2 if b_kern2>2 & b_kern2~=.
tab b_kern2 kat_b_kern2, m

gen kat_b_schuldhilfe3 = 1 if b_schuldhilfe3==3
replace kat_b_schuldhilfe3 = 0 if b_schuldhilfe3<3
replace kat_b_schuldhilfe3 = 2 if b_schuldhilfe3>3 & b_schuldhilfe3~=.
tab b_schuldhilfe3 kat_b_schuldhilfe3, m


lab var kat_b_skaloafd1 "start campaign AfD"
lab var kat_b_schuldhilfe3 "start campaign debt crisis" 
lab var kat_b_kern2 "start campaign nuclear energy"

fre kat*

* Labeln
lab var kat_changekerndir_25 "within campaign change nuclear energy (directed)"	
lab var kat_changekernabs_25 "within campaign change nuclear energy (undirected)"
lab var kat_changewslagedir_71 "between campaign change economy (directed)"
lab var kat_changewslagedir_17 "within campaign change economy (directed)"

lab var kat_changewslageabs_71 "between campaign change economy (undirected)"
lab var kat_changewslageabs_17 "within campaign change economy (undirected)"
lab var kat_changekandspdabs_71 "between campaign change SPD candidate (undirected)"
lab var kat_changekandspdabs_17 "within campaign change SPD candidate (undirected)"

lab var kat_changekandspddir_71 "between campaign change SPD candidate (directed)"
lab var kat_changekandspddir_17 "within campaign change SPD candidate (directed)"

lab var kat_changekandcduabs_71 "between campaign change CDU/CSU candidate (undirected)"
lab var kat_changekandcduabs_17 "within campaign change CDU/CSU candidate (undirected)"

lab var kat_changekandcdudir_71 "between campaign change CDU/CSU candidate (directed)"
lab var kat_changekandcdudir_17 "within campaign change CDU/CSU candidate (directed)"


lab var kat_changeskaloafddir_17 "within campaign change AfD (directed)"
lab var kat_changeskaloafdabs_17 "within campaign change AfD (undirected)"

lab var kat_changeschuldhilfedir_37 "within campaign change debt crisis (directed)"
lab var kat_changeschuldhilfeabs_37 "within campaign change debt crisis (undirected)"


*----------------------------------
* Data hygiene
*---------------------------------------

drop change*
drop b_kern2-b_kandspd7
